package com.by.biz.impl;

import com.by.biz.IUserBiz;
import com.by.dao.IUserDao;
import com.by.model.User;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userBiz")
public class UserBizImpl implements IUserBiz {
    @Autowired
    private IUserDao userDao;

    @Override
    public List<User> getAll() {
        return userDao.getAll();
    }

    @Override
    public int addUser(User user) {
        return userDao.addUser(user

   );
    }

    @Override
    public Page queryLikeUsers(Map<String, Object> cond) {
        Page page = new Page();
        page.setTotal(userDao.getLikeUsersCount(cond));

        int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);

        int curPageNum=Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(curPageNum);

        page.setPageNum((int)(page.getTotal()/pageSize+(page.getTotal()%pageSize==0?0:1)));

        page = PageHelper.startPage(curPageNum,pageSize);
        List list=userDao.getLikeUsers(cond);

        return page;
    }
}
